(function(){
    Ext.onReady(function(){
        Ext.define('MyApp.view.Signin',{
            extend: 'Ext.form.Panel',
            alias: 'widget.Signin',
            // requires: [
            //     'MyApp.view.controller.Users',
            // ],
            width: 400,
            height: 200,
            frame: true,
            //layout: 'fit',//'anchor',
            id: 'mySignin',
            title: 'Form Panel注册',
            bodyPadding: 5,
            defaultType: 'textfield',
            items: [{
                fieldLabel: '用户名',
                id:'username',
                name: 'username',
                maxLength:25,
                value:'aaaa',
                allowBlank: false
            },{
                fieldLabel: '密码',
                id:'password',
                name: 'password',
                inputType: 'password',
                minLength:6,
                maxLength:25,
                allowBlank: false
            },
            {
                fieldLabel: '确认密码',
                id:'qrpassword',
                name: 'qrpassword',
                inputType: 'password',
                minLength:6,
                maxLength:25,
                allowBlank: false
            }
            
            ,{xtype:'checkbox',
               boxLabel: '记住密码',
               name:'topping',
               inputValue: '1',
               id: 'checkbox1'
            }],
            buttons:[{
                text:'忘记密码',
                id:'forgetpwd',
                name:'forgetpwd',
                handler:function(){
                    console.log('forgetpwd');
                }
            },{
                text:'重置',
                id:'reset',
                name:'reset',
                handler:function(btn){
                    console.log(btn.ownerCt.ownerCt.queryById('username'));
                    console.log('reset');
                    console.log(Ext.get('username'));
                    console.log(Ext.get('username').id);
                    console.log(btn.ownerCt.ownerCt.queryById('username').value);
                    //console.log(Ext.get('username').getValue());
                    //Ext.get('username').value = '';
            }},{
                text:'提交',
                id:'submit',
                name:'submit',
                handler:function(btn){
                    console.log('submit');
                    var username = btn.ownerCt.ownerCt.queryById('username').value;
                    var password = btn.ownerCt.ownerCt.queryById('password').value;
                    var qrpassword = btn.ownerCt.ownerCt.queryById('qrpassword').value;
                    if(password !== qrpassword){
                        Ext.Msg.alert('注意','两次密码输入不一致');
                    }else{
                        Ext.Ajax.request({
                            //url: 'page.php',
                            url: 'regist',
                            timeout: 60000,
                            cors:true,
                            method: 'POST',
                            params: {
                                id: 1,
                                username: username,
                                password: password,
                                qrpassword: qrpassword
                            },
                            success: function(response, opts){
                                //var text = Ext.decode(response.responseText);
                                var text = response.responseText;
                                // process server response here
                                console.dir(text);
                                alert(response.responseText);
                                //console.log(doucument.baseURI);
                                var strurl = Ext.getDom('mySignin').baseURI;;
                                var iindex = strurl.lastIndexOf('/admin');
                                if(response.status == 200){
                                    var s1 = strurl.slice(0, iindex + 1) + 'admin/login';
                                    console.log('重定向页面' + s1);
                                    //跳转到登录页面
                                    document.location.href = s1;
                                }
                            },
                            failure: function(response, opts) {
                                //alert(response.responseText);
                                console.log('server-side failure with status code ' + response.status);
                            }
                        });
                    }
                }
            }],
            renderTo: Ext.getBody()
        });
        var sigin1 = Ext.create('MyApp.view.Signin',{});
        sigin1.show();
    });
})();